<template>
  <el-row style="width: 80%">
    <!-- 公告列表 -->
    <el-table
      :data="annouceList"
      style="margin-left: 30px; margin-top: 20px; width: 95%"
    >
      <el-table-column label="公告" width="150" prop="announcementTitle">
      </el-table-column>
      <el-table-column label="时间" width="220" prop="time"> </el-table-column>
      <el-table-column label="课程" width="100" prop="crs"> </el-table-column>
      <el-table-column label="内容" prop="announcementContent">
        <template slot-scope="scope">
          <el-row>
            <el-card shadow="never">
              {{ scope.row.announcementContent }}
            </el-card>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
  </el-row>
</template>

<script>
import stuInfo from "../../store/student";
import global from "../../lib/global";
import axios from "axios";
import qs from "qs";

export default {
  computed: {
    courseList() {
      return stuInfo.getters.getCourseList;
    },
  },
  data() {
    return {
      annouceList: [],
    };
  },
  mounted() {
    // 获取每一门课程的通知
    this.courseList.forEach((course) => {
      let id = course.courseId;
      // console.log(course);
      axios
        .post("/api/showAllAnnouncements", qs.stringify({ courseId: id }))
        .then((res) => {
          // console.log("作业", res);
          if (res.data.announcementList != null) {
            res.data.announcementList.forEach((ann) => {
              ann.crs = course.course_name;
              ann.time = global.formatTimeString(ann.lastChangeTime);
              this.annouceList.push(ann);
            });
          }
          // console.log("列表变量", this.annouceList);
        })
        .catch((err) => {
          console.log("公告", err);
        });
    });
  },
};
</script>

<style>
</style>